<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script>
            var i=2;
            function doAdd(){

                //创建节点
                var p=document.createElement("p");
                //添加文本内容
                p.innerHTML="p"+i;
                i++;
                //获取父节点
                var div=document.querySelector("div");
                //父节点添加子节点
                div.appendChild(p);
            }
            function doDelete(){
                var ps=document.querySelectorAll("p");
                ps[ps.length-1].remove();
                i--;
            }
        </script>
    </head>
    <body>
        <input type="button" value="添加" onclick="doAdd()">
        <input type="button" value="删除" onclick="doDelete()">
        <div>
            <p>p1</p>
        </div>
    </body>
</html>